import { Subject } from 'rxjs';
import { Injectable } from '@angular/core';
import { Message } from '../models/message';
import { BaseService } from './base.service';

@Injectable({
  providedIn: 'root'
})
export class MessageService extends BaseService {

  newMessage$: Subject<Message> = new Subject();

  queryMessages(queryParams: IMessageQueryParams): Promise<Message[]> {
    const url = `api/message`;
    return this.get(url, { params: queryParams as any });
  }

  async createMessage(msg: Message) {
    const url = `api/message`;
    const result = await this.post(url, msg);
    this.newMessage$.next(msg);
    return result;
  }

  deleteMessage(id: string) {

  }

  async getAfterWorkdayDate(params: { fromDay: string; days: number }) {
    const url = `http://filegennet5.zepride.com/Tools/GetDayAfterWorkDay`;
    const result = await this.post(url, params, { absolutelyUrl: true });
    return result.data.result[0].Msg;
  }

  async sendSMS() {
    const url = `http://filegennet5.zepride.com/AliyunSendMsg/SendMobileMsg`;

  }

}

export interface IMessageQueryParams {
  orgId?: string;
  senderId?: string;
  receiverIds?: string[];
}
